/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Loggin.java
 *
 * Created on 29 juin 2011, 14:40:33
 */
package View;

import Model.Utilisateur;
import Model.Commande;
import Model.LigneCommande;
import Model.Plat;
import Model.Restaurant;
import java.util.ArrayList;


import Model.Utilisateur;
import com.sun.corba.se.spi.oa.OADefault;
import java.awt.Dialog.ModalExclusionType;

/**
 *
 * @author aj48450
 */
public class Loging extends javax.swing.JFrame {

    //private ViewCommande vueCommande = new ViewCommande();
    //private ViewLivraison vueLivraison = new ViewLivraison();
    private ArrayList<Utilisateur> utilisateurs;
    
    /** Creates new form Login */
    public Loging() {
        initComponents();
        
        utilisateurs = new ArrayList<Utilisateur>();
        
        utilisateurs.add( new Utilisateur("log210", "1100 Rue Notre-Dame Ouest", false ) );
        utilisateurs.add( new Utilisateur("Livreur2", "Mexico", true ) );
        utilisateurs.add( new Utilisateur("Livreur", "10555 av. de Bois-de-Boulogne MONTRÉAL, Québec H4N 1L4", true ) );
        utilisateurs.add( new Utilisateur("Client1", "925 rue Mireille Laval, QC", false )); 
        utilisateurs.add( new Utilisateur("Client", "925 rue Lambert Laval, QC", false )); 
        utilisateurs.add( new Utilisateur("Client2", "Matane, QC G4W 2 E3", false ) );
        
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        txtNom = new javax.swing.JTextField();
        btnLoggin = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        txtNom.setName("txtNom"); // NOI18N
        txtNom.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtNomActionPerformed(evt);
            }
        });

        btnLoggin.setText("Login");
        btnLoggin.setName("btnLoggin"); // NOI18N
        btnLoggin.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLogginActionPerformed(evt);
            }
        });

        jLabel1.setText("Entrez votre nom");
        jLabel1.setName("jLabel1"); // NOI18N

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(67, 67, 67)
                        .add(txtNom, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 190, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(layout.createSequentialGroup()
                        .add(107, 107, 107)
                        .add(jLabel1))
                    .add(layout.createSequentialGroup()
                        .add(121, 121, 121)
                        .add(btnLoggin)))
                .addContainerGap(52, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(36, 36, 36)
                .add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 16, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(txtNom, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(btnLoggin)
                .addContainerGap(30, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void login()
    {
        boolean type = false;
        String adresse = "";
        String nom = "";
        
        for ( Utilisateur u : utilisateurs )
        {
           if ( u.getNom().toLowerCase().compareTo(txtNom.getText().toLowerCase()) == 0 )
           {
              type = u.getTypeUtilisateur();
              adresse = u.getAdresse();
              nom = u.getNom();
              break;
           }
        }
        if ( !nom.equals(""))
        {
            //livreur
            if ( type )
                new ViewLivraison(adresse).setVisible(true);  
            //client
            else
                new ViewCommande(adresse, nom).setVisible(true);
        }
    }
    
    private void btnLogginActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLogginActionPerformed
        login();       
    }//GEN-LAST:event_btnLogginActionPerformed

    private void txtNomActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtNomActionPerformed
        login();
    }//GEN-LAST:event_txtNomActionPerformed

   
    
    
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new Loging().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnLoggin;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JTextField txtNom;
    // End of variables declaration//GEN-END:variables
}
